package com.egg.auth.enums.account;


import cn.hutool.core.util.ObjectUtil;
import com.egg.common.core.exception.CustomException;
import com.egg.common.swagger.annotation.SwaggerDisplayAnnotation;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

/**
 * 设备类型枚举类
 *
 * @author east
 */
@Getter
@SwaggerDisplayAnnotation
@AllArgsConstructor
public enum DeviceTypeEnum {


    WEB("网页端", "web"),
    IOS("苹果端", "ios"),
    ANDROID("安卓端", "android"),

    ;


    private String message;
    private String code;


    public static DeviceTypeEnum get(String code) {
        if (ObjectUtil.isEmpty(code)) {
            throw new CustomException("设备类型无效");
        }
        Optional<DeviceTypeEnum> any = Arrays.stream(values()).filter(o -> Objects.equals(code, o.getCode())).findAny();
        if (!any.isPresent()) {
            throw new CustomException("设备类型无效");
        }
        return any.get();
    }

    @Override
    public String toString() {
        return message + ":" + code;
    }
}
